const MovieHttp = require("../../utils/MovieHttp")
Page({

  data: {
    dif:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    var {
      url
    } = options;
    var top250 = "4000/api/movie/top250";
    var inTheaters = "4000/api/movie/inTheaters";
    var comingSoon = "4000/api/movie/comingSoon"
    var arr = [top250,comingSoon,inTheaters];
    if(url==arr[0]){
      var top = await MovieHttp.getHttp(url);
      // console.log(top);
      top.data.res.forEach(item=>{
        var {rating} = item;
        item.star = MovieHttp.handleStar(rating)
      })
      // console.log(dif);
      this.setData({
        dif:top.data.res
      })
    }else if(url==arr[1]){
      var coming = await MovieHttp.getHttp(url);
      console.log(coming);
      coming.data.res.forEach(item=>{
        var {rating} = item;
        item.star = MovieHttp.handleStar(rating)
      })
      // console.log(dif);
      this.setData({
        dif:coming.data.res
      })
    }else if(url==arr[2]){
      var theaters = await MovieHttp.getHttp(url);
      console.log(theaters.data.res);
      theaters.data.res.forEach(item=>{
        var {raiting} = item;
        item.star = MovieHttp.handleStar(raiting)
        item.rating = raiting;
      })
      // console.log(dif);
      this.setData({
        dif:theaters.data.res
      })
    }

  },
  Onclick(e){
    var {aid} = e.currentTarget.dataset;
    console.log(aid);
    wx.navigateTo({
      url: `../movieDetail/movieDetail?id=${aid}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})